import Opt from '@/components/dt/info/Opt.js'
import table from '@/components/dt/table/render.js'
import nameOpt from '@/biz/option/name.js'
import dateOpt from '@/biz/option/date.js'
let _this = null
class Column extends Opt {

  constructor(vm) {
    super()
    _this = vm
    this.build()
  }

  build() {
    this.createAll()
    this.opts.push(...this.all)
  }


  createAll() {
    this.all = [

      {
        field: 'userName',
        title: '姓名',
        minWidth: 200,
        align: 'center',

        header: {
          filter: nameOpt.createPeople({
            key: 'userName',
            title: '姓名',
            to: (info) => {
              return {
                userName: info.userName
              }
            }
          })
        },
        slots: {
          default: (params, h) => {
            return table.cell.text(h, {
              value: `${params.row.userName}（${params.row.workNo}）`
            })
          }
        }

      },


      {
        field: 'phone',
        title: '手机号码',
        minWidth: 200,
        header: {
          filter: {
            title: '手机号码',
            key: 'phone',
            placeholder: '请输入手机号码',
            input: {}
          }
        },
      },
      {
        field: 'authStatus',
        title: '授权状态',
        minWidth: 200,
        header: {
          filter: {
            title: '授权状态',
            key: 'authStatus',
            placeholder: '请选择',
            select: {
              // 1.已授权，2.已过期，3.已解绑
              options: [{ key: 1, value: '已授权' }, { key: 2, value: '已过期' }, {
                key: 3,
                value: '已解绑'
              }]
            }
          }
        }
      },

      {
        title: '授权时间',
        field: 'authTime',
        minWidth: 180,
        header: {
          filter: dateOpt.range({
            title: '授权时间',
            startKey: 'registerTimeStart',
            endKey: 'registerTimeEnd',
            disabled: (date) => {
              return date.valueOf() > new Date().getTime()
            },
            check: (val) => {
              if (_this.$tool.dateDiff(val.registerTimeStart, val
                  .registerTimeEnd).Y >= 2) {
                // 日期最大跨度两年
                _this.$Message.warning('签约日期跨度至多两年。')
              }
              return !(_this.$tool.dateDiff(val.registerTimeStart, val
                .registerTimeEnd).Y >= 2)
            }
          }),
        },
        // slots: {
        //   default: (params, h) => {
        //     return table.cell.text(h, {
        //       value: params.row.authTime ? params.row.authTime : '已解绑'
        //     })
        //   }
        // }
      },
      {
        title: '更新时间',
        field: 'createTime',
        minWidth: 150,
      },
      {
        title: '授权后新增视频数',
        field: 'newVideo',
        minWidth: 150,
      },
      {
        title: '授权后新增粉丝数',
        field: 'newFans',
        minWidth: 150,
      },
      {
        title: '授权后新增点赞数',
        field: 'newFabulous',
        minWidth: 150,
      },
      {
        title: '授权后新增分享数',
        field: 'newSharing',
        minWidth: 150,
      },
      {
        title: '授权后新增主页访问',
        field: 'newVisit',
        minWidth: 150,
      },
      {
        title: '所属事业部',
        field: 'orgDivisionName',
        minWidth: 150,
      }, {
        title: '所属子公司',
        field: 'orgCompanyName',
        minWidth: 150,
      }, {
        title: '所属事业处',
        field: 'orgOfficeName',
        minWidth: 150,
      },
      {
        field: 'handles',
        title: '操作',
        width: 150,
        fixed: 'right',
        align: 'center',
        slots: {
          default: (params, h) => {
            return [
              h(
                'Button', {
                  props: {
                    type: 'text',
                  },
                  style: {
                    cursor: 'pointer',
                    padding: '0 5px',
                    color: '#0F42A7'
                  },
                  on: {
                    click: (e) => {
                      e.stopPropagation()
                      _this.getDetail(params.row)
                    },
                  },
                },
                '查看详情'
              ),
            ]
          }
        }
      }
    ]
  }

}

export default Column